package com.dodoke.config;

import com.dodoke.provider.WechatAuthenticationProvider;
import org.springframework.security.config.annotation.SecurityConfigurerAdapter;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.web.DefaultSecurityFilterChain;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 自定义微信openId验证组件配置
 */
@Component
public class WechatSecurityConfig extends SecurityConfigurerAdapter<DefaultSecurityFilterChain, HttpSecurity> {

    /**
     * 自定义短信验证码用户认证逻辑
     */
    @Resource(name = "WxUserDetailServiceImpl")
    private UserDetailsService wechatUserDetailsService;


    @Override
    public void configure(HttpSecurity http) throws Exception {
        //设置UserDetailsService
        WechatAuthenticationProvider wechatAuthenticationProvider = new WechatAuthenticationProvider();
        wechatAuthenticationProvider.setUserDetailsService(wechatUserDetailsService);
        //这里说明要把我们自己写的Provider放在过滤链的哪里
        http.authenticationProvider(wechatAuthenticationProvider);
    }


}